<?php

namespace App\Http\Controllers\Back;

use App\Http\Controllers\Controller;
use App\Model\Member;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Swagger\Annotations as SWG;

class MemberController extends Controller
{
    public function index(Request $request)
    {

        $m = new Member();
        return $this->renderJson($m->lists());
    }

    /**
     * @SWG\Get(
     *     path="/back/member/{id}",
     *     tags={"后台"},
     *     summary="会员详情",
     *     description="会员详情",
     *     @SWG\Parameter(ref="#/parameters/auth"),
     *     @SWG\Parameter(name="id", in="path", type="integer", description="id"),
     *     @SWG\Response(
     *          response="200",
     *          description="ok",
     *          @SWG\Schema(
     *              @SWG\Property(property="vip_name", type="string", description="vip"),
     *              @SWG\Property(property="user_name", type="string", description="用户"),
     *              @SWG\Property(
     *                  property="personal_page",
     *                  type="array",
     *                  description="个人网页",
     *                  @SWG\Items(
     *                      @SWG\Property(property="id", type="integer", description="id"),
     *                      @SWG\Property(property="name", type="string", description="模板"),
     *                      @SWG\Property(property="content", type="string", description="内容"),
     *                  )
     *              ),
     *              @SWG\Property(
     *                  property="marketiong",
     *                  type="array",
     *                  description="营销网页",
     *                  @SWG\Items(
     *                      @SWG\Property(property="id", type="integer", description="id"),
     *                      @SWG\Property(property="name", type="string", description="名字"),
     *                      @SWG\Property(property="content", type="string", description="内容"),
     *                  )
     *              ),
     *          )
     *      )
     * )
     */
    public function show()
    {
        $id = \request('id');
        $data = DB::table('cards as c')->select('c.*','cf.name as vip_name')
            ->leftJoin('user_grade as ug', 'c.user_id', 'ug.user_id')
            ->leftJoin('vip_fee_config as cf', 'ug.vip_fee_config_id', 'cf.id')
            ->where('c.user_id', $id)->first();
        if ($data) {
            $data->personal_page = DB::table('personal_page_template_user as u')->select('u.id', 't.name', 'u.content')->leftJoin('personal_page_template as t', 'u.template_id', 't.id')->where('u.user_id', $id)->get();
            $data->marketing = DB::table('user_marketing')->select('id', 'title as name', 'contents')->where('user_id', $id)->get();
        }
        return $this->renderJson($data);
    }
}
